package sk.xorty.si;

import org.springframework.integration.annotation.Router;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Component
public class ProductRouter {

    private static final Map<String, String> ROUTES;

    static {
        ROUTES = new HashMap<String, String>();
        ROUTES.put(MessageTypes.TYPE_SALES, "salesChannel");
        ROUTES.put(MessageTypes.TYPE_INVENTORY, "inventoryChannel");
        ROUTES.put(MessageTypes.TYPE_ORDER, "orderChannel");
    }

    @Router
    public String route(String[] contents) {
        System.out.println("======== ROUTING MESSAGE ========");
        String channel = ROUTES.get(contents[MessageTypes.TYPE_INDEX]);
        System.out.println("\t=> Message: " + Arrays.toString(contents));
        System.out.println("\t=> Routing result: " + channel);
        return null == channel ? "unknownChannel" : channel;
    }

}
